package controllers

import (
	"doctor/models"
	beego "github.com/beego/beego/v2/server/web"
)

type UserControllers struct {
	beego.Controller
}
type Json struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

func (c *UserControllers) Page() {
	page, _ := c.GetInt("p", 1)
	Size, _ := c.GetInt("s", 5)
	user, count, err := models.Page(page, Size)
	if err != nil {
		c.Data["json"] = Json{
			Code: 500,
			Msg:  "展示失败",
			Data: nil,
		}
		c.ServeJSON()
	} else {
		pageData := make(map[string]interface{})
		pageData["user"] = user
		pageData["count"] = count
		c.Data["json"] = Json{
			Code: 200,
			Msg:  "展示成功",
			Data: pageData,
		}
		c.ServeJSON()
	}
}
